package com.example.tests;

import static org.junit.Assert.assertThat;
import org.testng.annotations.Test;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import org.testng.annotations.DataProvider;
//import static com.example.tests.ContactDataGenerator.loadContactsToCsvFile;
//import com.example.tests.ContactDataGenerator.loadContactsToXmlFile;
import com.example.tests.ContactDataGenerator.*;
import static org.hamcrest.Matchers.*;
import com.example.utils.SortedListOf;

public class ContactCreation extends AddressbookTestBase{

		@DataProvider
		public Iterator<Object[]> contactsFromFile() throws IOException{	
			File file = new File("contacts.xml");
			ContactDataGenerator contik = new ContactDataGenerator();
			List<ContactData> loadContactsToXmlFile = contik.loadContactsToXmlFile(file);
			return wrapContactsForDataProvider(loadContactsToXmlFile).iterator();		
		}
	
		@Test(dataProvider = "contactsFromFile")
		public void testValidContactCreation(ContactData contactInput) throws Exception {
			//save old state
			SortedListOf<ContactData> oldList = app.getContactHelper().getContacts();
			//actions
			app.getContactHelper().creationContact(contactInput);		
			//save new state
			SortedListOf<ContactData> newList = app.getContactHelper().getContacts();		
			//compare states		
			assertThat(newList, equalTo(oldList.withAdded(contactInput)));			
		}
}
